package cn.wolfcode.service.impl;

import cn.wolfcode.domain.SysDictData;
import cn.wolfcode.mapper.SysDictDataMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.ISysDictDataService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * ClassName SysDictDataServiceImpl
 * Create by Mike
 * Date 2021/8/1 16:46
 */
@Service
@Transactional
@Setter
@Slf4j
public class SysDictDataServiceImpl implements ISysDictDataService {

    @Autowired
    private SysDictDataMapper sysDictDataMapper;

    @Override
    public void save(SysDictData sysDictData) {
        // TODO: 2021/8/18 正常还要加入判断存入数据是否在数据库中有重复的代码
        sysDictDataMapper.insert(sysDictData);
    }

    @Override
    public void delete(Long id) {
        sysDictDataMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(SysDictData sysDictData) {
        sysDictDataMapper.updateByPrimaryKey(sysDictData);
    }

    @Override
    public SysDictData get(Long id) {
        return sysDictDataMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysDictData> listAll() {
        return sysDictDataMapper.selectAll();
    }

    @Override
    public PageInfo<SysDictData> query(QueryObject qo) {

        //使用分页插件,传入当前页,每页显示数量
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());

        List<SysDictData> sysDictDatas = sysDictDataMapper.selectForList(qo);

        return new PageInfo(sysDictDatas);
    }

    @Override
    public List<SysDictData> queryByType(String type) {
        return sysDictDataMapper.selectByType(type);
    }
}
